import { createStore, Store } from 'vuex';
import createPersistedstate from 'vuex-persistedstate';
// 为 store state 声明类型
export interface State {
  token: snumber;
  count: number;
}
const plugins = [
  createPersistedstate({
    // // 哪些模块需要被缓存
    // paths: ['user', 'cart']
    // storage: window.sessionStorage,
    // reducer(val: State) {
    //   return {
    //     // 只储存state中的count
    //     count: val.count
    //   };
    // }
  })
];
export const store = createStore<State>({
  state() {
    return {
      token: '',
      count: 0
    };
  },
  mutations: {
    saveToken(state, val) {
      state.token = val;
    },
    addCount(state, val) {
      state.count = val;
    }
  },
  plugins
});
